package com.feiluan.rest.controller;

import com.alibaba.fastjson.JSONObject;
import com.feiluan.service.HaierService;

import com.google.gson.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
public class HaierController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    HaierService haierService;

    @RequestMapping(value = "/haier/login", method = RequestMethod.GET)
    public ResponseEntity<String> haierLogin() {

        return haierService.postLogin();
    }

    @RequestMapping(value = "/haier/token", method = RequestMethod.GET)
    public ResponseEntity<String> haierToken() {
        return haierService.postToken();
    }

    @RequestMapping(value = "/haier/tokeninfo", method = RequestMethod.GET)
    public ResponseEntity<String> haierTokenInfo() {
        return haierService.postTokenInfo();
    }

    @RequestMapping(value = "/haier/deviceinfos", method = RequestMethod.GET)
    public ResponseEntity<String> haierDeviceinfos() {
        return haierService.getDeviceinfos();
    }

    @RequestMapping(value = "/haier/sign", method = RequestMethod.POST)
    public Map<String, String> haierSign(
            @RequestParam(value = "body", required = false, defaultValue = "") String body,
            @RequestParam(value = "uri", required = true) String uri) {
        logger.info("body is : " + body, "uri is : " + uri);

        return haierService.getSign(body, uri);
    }

    @RequestMapping(value = "/haier/propertyWrite", method = RequestMethod.POST)
    public ResponseEntity<String> haierPropertyWrite(@RequestBody String jsonParam) {
        logger.info("jsonParam is  : " + jsonParam);
        return haierService.postPropertyWrite(jsonParam);
    }


    @RequestMapping(value = "/haier/callback", method = RequestMethod.POST)
    public ResponseEntity<String> haierCallback(@RequestBody String callBackInfo) {
        logger.info("callBackInfo is  : " + callBackInfo);
        return haierService.postPropertyWrite(callBackInfo);
    }


}
